package com.ruoyi.jksd.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.jksd.common.dto.XyRechargeDto;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.jksd.domain.XyRecharge;
import com.ruoyi.jksd.service.IXyRechargeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 会员-充值Controller
 * 
 * @author ruoyi
 * @date 2024-05-26
 */
@RestController
@RequestMapping("/xyrecharge/xyrecharge")
public class XyRechargeController extends BaseController
{
    @Autowired
    private IXyRechargeService xyRechargeService;

    /**
     * 查询会员-充值列表
     */
    @PreAuthorize("@ss.hasPermi('xyrecharge:xyrecharge:list')")
    @GetMapping("/list")
    public TableDataInfo list(XyRecharge xyRecharge)
    {
        startPage();
        List<XyRecharge> list = xyRechargeService.selectXyRechargeList(xyRecharge);
        return getDataTable(list);
    }

    /**
     * 导出会员-充值列表
     */
    @PreAuthorize("@ss.hasPermi('xyrecharge:xyrecharge:export')")
    @Log(title = "会员-充值", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, XyRecharge xyRecharge)
    {
        List<XyRecharge> list = xyRechargeService.selectXyRechargeList(xyRecharge);
        ExcelUtil<XyRecharge> util = new ExcelUtil<XyRecharge>(XyRecharge.class);
        util.exportExcel(response, list, "会员-充值数据");
    }

    /**
     * 获取会员-充值详细信息
     */
    @PreAuthorize("@ss.hasPermi('xyrecharge:xyrecharge:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(xyRechargeService.selectXyRechargeById(id));
    }

    /**
     * 新增会员-充值
     */
    @PreAuthorize("@ss.hasPermi('xyrecharge:xyrecharge:add')")
    @Log(title = "会员-充值", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody XyRecharge xyRecharge)
    {
        return toAjax(xyRechargeService.insertXyRecharge(xyRecharge));
    }

    @Log(title = "会员-充值", businessType = BusinessType.INSERT)
    @PostMapping("/applyRecharge")
    public AjaxResult applyRecharge(@RequestBody XyRechargeDto xyRecharge)
    {
        return xyRechargeService.recharge(xyRecharge);
    }

    @PreAuthorize("@ss.hasPermi('xyrecharge:xyrecharge:add')")
    @Log(title = "会员-充值", businessType = BusinessType.INSERT)
    @PostMapping("/approveRecharge")
    public AjaxResult approveRecharge(@RequestBody XyRecharge xyRecharge)
    {
        return xyRechargeService.approveRecharge(xyRecharge);
    }

    /**
     * 修改会员-充值
     */
    @PreAuthorize("@ss.hasPermi('xyrecharge:xyrecharge:edit')")
    @Log(title = "会员-充值", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody XyRecharge xyRecharge)
    {
        return toAjax(xyRechargeService.updateXyRecharge(xyRecharge));
    }

    /**
     * 删除会员-充值
     */
    @PreAuthorize("@ss.hasPermi('xyrecharge:xyrecharge:remove')")
    @Log(title = "会员-充值", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(xyRechargeService.deleteXyRechargeByIds(ids));
    }
}
